﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
@* 导出引入文件 *@
<title>Layui with XLSX</title>
<!-- 引入Layui的CSS -->
@* <link rel="stylesheet" href="path/to/layui.css"> *@
<!-- 引入XLSX库的CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>采购入库列表</title>
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
            <div class="demo-login-container">
                <div class="layui-form-item">
                    <div class="layui-input-group">

                         <div class="layui-input-group">
                              <div class="layui-input-prefix" style="left:28px">
                                             物料编码
                              </div>
                                  <div style="width:150px;left:28px">
                                    <input style="width:150px" type="text" name="productManageNode" value="" lay-verify="required" placeholder="请输入物料编码" lay-reqtext="请填写物料编码" autocomplete="off" class="layui-input" lay-affix="clear">
                                  </div>
                                   <div style="left:19px">
                                     <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customs">
                                     <i class="layui-icon layui-icon-search"></i>
                                      </button>
                                   </div>
                              </div>
                    </div>
                        
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            物料名称
                        </div>
                        <div style="width:500px;left:28px">
                        <input style="width:500px" type="text" name="productManageName" value="" lay-verify="required" placeholder="请输入物料名称" lay-reqtext="请填写物料名称" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            单位
                        </div>
                        <div style="width:500px;left:28px">
                        <input style="width:500px" type="text" name="unites" value="" lay-verify="required" placeholder="请输入单位" lay-reqtext="请填写单位" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>

                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            入库数量
                        </div>
                        <div class="layui-input-inline" style="width: 100px; left: 28px">
                            <input type="number" name="Num" placeholder="" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            入库仓库
                        </div>
                        <div style="width:300px;left:30px">
                            <select style="width:300px" name="stashName" id="stashId">
                                <option value="0">请选择</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        有效期
                    </div>
                    <div class="layui-input-inline layui-input-wrap" style="left:28px">
                        <div class="layui-input-prefix" >
                            <i class="layui-icon layui-icon-date" ></i>
                        </div>
                        <input type="text"  name="MaterialTime" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        入库批次号
                    </div>
                    <div style="width:500px;left:28px">
                        <input style="width:500px" type="text" name="Batch" value="" lay-verify="required" placeholder="请输入物料名称" lay-reqtext="请填写物料名称" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        备注
                    </div>
                    <div style="width:300px;left:28px">
                        <textarea style="width:400px" type="textarea" name="Remark" value="" lay-verify="required" placeholder="请输入备注" lay-reqtext="请填写备注" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-form-item" style="left:200px">
                        <button type="submit" class="layui-btn layui-btn-normal" lay-submit lay-filter="demo-login">新增</button>
                        <button class="layui-btn layui-btn-primary" lay-filter="demo-Break">取消</button>
                    
                    </div>
                </div>
            </div>
        
    </form>
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
            <a class="layui-btn layui-btn-xs" lay-event="YesWang">选择</a>
        </div>
    </script>
<script>

        layui.use(['form', 'laydate', 'util'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            // 日期
            laydate.render({
                elem: '#date'
            });
            $(function () {
                GetStash();
            })
          
            
            //仓库下拉框
            function GetStash() {
                $.ajax({
                    url: '@ViewBag.FoundationWrite' + '/api/Jocker/warehouseList',
                    data: JSON.stringify({}),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res.data);
                        $.each(res.data, function () {
                            $("#stashId").append(`<option value="${this.stashId}">${this.stashName}</option>`);
                        });
                        form.render('select');//重新渲染下拉框
                    }
                })
            }
            // 提交事件
            form.on('submit(demo-login)', function (data) {
                var field = data.field; // 获取表单字段值
                field.State = 0;
                var field = data.field; // 获取表单字段值
                var datec = new Date()
                var year = datec.getFullYear();
                var month = (datec.getMonth() + 1).toString().padStart(2, "0")
                var date = (datec.getDate() + 1).toString().padStart(2, "0")
                var hours = datec.getHours()
                var minute = (datec.getMinutes()).toString().padStart(2, "0")
                var seconds = (datec.getSeconds()).toString().padStart(2, "0")
                // var Encoding = "IF";
                var result = "CX" + year + month + date + hours + minute + seconds;
                console.log(result);
                let obj = {
                    ProductManageId: localStorage.getItem("productManageId"),
                    Num: $("[name='Num']").val(),
                    Batch: $("[name='Batch']").val(),
                    StashId: $("#stashId").val(),
                    MaterialTime: $("[name='MaterialTime']").val(),
                    remark: $("[name='Remark']").val(),
                    SupplierId:0,
                    MaterialNo: result,
                    PurchaseNo:localStorage.getItem("purchaseNo")
                }
                console.log(obj,'1111111111');
                $.ajax({
                    url: '@ViewBag.FoundationWrite' + "/api/Jocker/MaterialAdd",
                    data: JSON.stringify(obj),
                    type: "post",
                    contentType: "application/json",
                    success: function (res) {

                        console.log(res.data);
                        if (res.code > 0) {
                            layer.alert("添加成功");
                        }
                        else {
                            alert('提交失败')
                        }
                    }
                })

                return false;
            });
        });
       

</script>
<script>
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        layui.use(function () {
            // 事件
            util.on('lay-on', {
                'test-page-customs': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title:'物料管理',
                             content: `
                          <form class="layui-form" action="">
                                    <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                                        <div class="layui-form-item">
                                            <div class="demo-Add-container">
                                                <table style="left:320px" class="layui-hide" id="ID-table-demo-datasd" lay-filter="ID-table-demo-datasd"></table>
                                            </div>
                                        </div>
                                    </div>
                                </form>
            `,
              success: function () {
                            var form = layui.form;
                            var laypage = layui.laypage;
                            var layer = layui.layer;
                            var $ = layui.$;
                            var laydate = layui.laydate;
                            var util = layui.util;
                            var table = layui.table;

                            var pageIndex = 1;
                            var pageSize = 2;

                            $(function () {
                                ShowSupplier(pageIndex, pageSize);
                            })
                            //物料列表
                            function ShowSupplier(pageIndex, pageSize) {
                                let obj = {
                                    pageIndex: pageIndex,
                                    pageSize: pageSize
                                }
                                var inst = table.render({
                                    elem: '#ID-table-demo-datasd',
                                    method: 'post',
                                    contentType: 'application/json',
                                    toolbar: '#toolbarDemo',
                                    defaultToolbar: ['filter', 'exports', 'print', { // 右上角工具图标
                                        title: '提示',
                                        layEvent: 'LAYTABLE_TIPS',
                                        icon: 'layui-icon-tips',
                                        onClick: function (obj) { // 2.9.12+
                                            layer.alert('自定义工具栏图标按钮');
                                        }
                                    }],
                                    url: '@ViewBag.FoundationWrite' + '/api/Jocker/ProductList',
                                    where: obj,
                                    cols: [[
                                        { field: 'productManageNode', title: '物料编码', width: 200 },
                                        { field: 'productManageName', title: '物料名称', width: 200 },
                                        { field: 'productManageNumber', title: '规格型号', width: 200 },
                                        { field: 'unites', title: '单位', width: 200 },
                                        { fixed: 'right', title: '操作', width: 140, minWidth: 140, templet: '#toolDemo' }
                                    ]],
                                    page: false,
                                    height: 310,
                                    done: function (res) {
                                        var id = this.id;
                                        console.log(res);// 你可以在这里检查返回的数据结构是否符合预期
                                        // 触发单元格工具事件
                                        //分页数据
                                        laypage.render({
                                            elem: 'demo-laypage-alles', // 元素 id
                                            count: res.totalCount, // 数据总数
                                            curr: pageIndex,
                                            limit: pageSize,
                                            limits: [2, 3, 4],
                                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                            jump: function (obj, first) {
                                                if (!first) {
                                                    ProductionSearch(obj.curr, obj.limit);
                                                }
                                            }
                                        });
                                    }
                                })
                                table.on('tool(ID-table-demo-datasd)', function (obj) { // 双击 toolDouble
                                    var data = obj.data; // 获得当前行数据
                                    localStorage.setItem("productManageId", data.productManageId);
                                    console.log(data)
                                    if (obj.event === 'YesWang') {
                                        $("[name='productManageNode']").val(data.productManageNode);
                                        $("[name='productManageName']").val(data.productManageName);
                                        $("[name='unites']").val(data.unites);
                                        $("[name='productManageNumber']").val(data.productManageNumber);
                                        localStorage.setItem("materialNo", data.materialNo);
                                        // 对弹层中的表单进行初始化渲染
                                        form.render();
                                        layer.close(layer.index); // 关闭弹层
                                    }
                                });
                            }


                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            // 表单提交事件
                            form.on('submit(demo-Search)', function (data) {
                                var field = data.field; // 获取表单字段值

                                // 显示填写结果，仅作演示用
                                // layer.alert(JSON.stringify(field), {
                                //     title: '当前填写的字段值'
                                // });
                                // 此处可执行 Ajax 等操作
                                // …

                                return false; // 阻止默认 form 跳转
                            });
                        }
                    });
                }
            })
        });
      
    </script>
</body>
</html>
